<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


  <script>

    function Person(name, age) {
      this.name = name;
      this.age = age;
    }
    // 父类的原型对象属性
    Person.prototype.id = 10;

    // 子类
    function Boy(name, age, sex) {
      //call或apply 实现继承
      Person.call(this, name, age);
      this.sex = sex;
    }

    // 原型继承实现 Object.create(Animal.prototype):创建一个新对象，使用现有的对象来提供新创建的对象的__proto__
    Boy.prototype = Object.create(Person.prototype)
    // 覆盖子类的prototype后保证子类中prototype的完整性
    Boy.prototype.constructor = Boy;
    var b = new Boy('c5', 27, '男');
    var p = new Person('a', 28, '女');
    console.log(b);
    console.log(p);
    console.log(b.name);// c5
    console.log(b.id);//10



    var add = function () {
      console.log(arguments);
      let sum = 0;
      for (let i = 0; i < arguments.length; i++) {
        sum += arguments[i];
      }
      return sum;
    };

    var proxyAdd = function () {
      console.log(arguments);
      return add.apply(null, arguments);
    };
    console.log(proxyAdd(1, 2, 3, 4, 5)); //15



  </script>
</body>

</html>